#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time     : 2021/6/25 15:54
# @Author   : chengfeng
# @Email    : chengfeng@inhand.com.cn
# @File     : Assert.py

import allure


@allure.step('验证元素placeholder值')
def placeholder(page, selector: str, value):
    """
    验证元素placeholder值
    :param page: 打开的页面
    :param selector: 元素定位
    :param value: 期待验证的值是否相等
    :return:
    """
    try:
        assert page.get_attribute(selector, 'placeholder') == value, "{} page {} placeholder is not {}".format(
            page, selector, value)
    except AssertionError:
        raise


@allure.step('验证元素可见')
def is_visible(page, selector: str):
    """
    验证元素可见
    :param page:  页面
    :param selector:  元素定位
    :return:
    """
    try:
        assert page.is_visible(selector), "{} page element {} is not visible".format(page, selector)
    except AssertionError:
        raise


@allure.step('验证inner_text')
def inner_text(page, selector: str, value):
    """
    验证inner_text
    :param page:    页面
    :param selector:    元素定位
    :param value:   值
    :return:
    """
    try:
        assert page.inner_text(selector) == value, "{} page element {}, inner_text is not {}".format(page, selector,
                                                                                                     value)
    except AssertionError:
        raise


@allure.step('验证inter_html')
def inner_html(page, selector: str, value):
    """
    验证inner_html
    :param page:    页面
    :param selector:    元素定位
    :param value:   值
    :return:
    """
    try:
        assert page.inner_html(selector) == value, '{} page element {}, inner_html is not {}'.format(page, selector,
                                                                                                     value)
    except AssertionError:
        raise


@allure.step('验证元素可用')
def is_enable(page, selector: str):
    """
    验证元素可用
    :param page:    页面
    :param selector:    元素定位
    :return:
    """
    try:
        page.is_enable(selector), "{} page element {} is disable".format(page, selector)
    except AssertionError:
        raise


@allure.step('验证text_content')
def text_content(page, selector: str, value):
    """
    验证text_content
    :param page:    页面
    :param selector:    元素定位
    :param value:   值
    :return:
    """
    try:
        page.text_content(selector) == value, "{} page element {}, text_content is not {}".format(page, selector,
                                                                                                  value)
    except AssertionError:
        raise
